package org.canda.spring6.resource;

import org.springframework.core.io.ClassPathResource;

import java.io.IOException;
import java.io.InputStream;

/**
 * 访问类路径下的资源
 */
public class ClassPathResourceDemo {


    public static void main(String[] args) {
        loadClassPathResource("reTest.txt");
    }

    public static  void loadClassPathResource(String path){
        ClassPathResource pathResource = new ClassPathResource(path);
        System.out.println(pathResource.getFilename());
        try {
            InputStream inputStream = pathResource.getInputStream();
            byte[] data = new byte[1024];
            inputStream.read(data);
            System.out.println(new String(data));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
